package com.example.cloudsampleprovider.contoller;

import com.example.cloudsampleprovider.model.TestModel;
import com.example.cloudsampleprovider.service.TestModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class TestModelController {
    @Value("${server.port}")
    private String port;
    @Autowired
    private TestModelService testModelService;

    @RequestMapping("/model/{id}")
    public Object getById(@PathVariable("id") Integer id) {
        TestModel byId = testModelService.getById(id);
        HashMap<String, Object> map = new HashMap<>();
        map.put("port", port);
        map.put("TestModel", byId);
        return map;
    }

    @RequestMapping("/model/save")
    public boolean save(@RequestBody TestModel testModel) {
        boolean save = testModelService.save(testModel);
        return save;
    }

}
